<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="/WEB-INF/layout/template.xhtml">

    <ui:define name="navigation">
        <p:breadCrumb>
            <p:menuitem value="首页" url="/index.xhtml"/>
            <p:menuitem value="系统管理" url="#"/>
            <p:menuitem value="用户管理" url="#"/>
        </p:breadCrumb>
    </ui:define>

    <ui:define name="helpInfo">
        <p:panel>
            <h:outputText class="ui-icon ui-icon-lightbulb" style="display: inline-block"/>
            用户管理<br/>
            帮助信息……
        </p:panel>
    </ui:define>

    <ui:define name="content">
        <h:form id="userQueryForm">
            <p:fieldset legend="查询条件" toggleable="true">
                <h:panelGrid columns="3">
                    <h:panelGroup>
                        <p:outputLabel for="username" value="用户名："/>
                        <p:inputText id="username"
                                     value="#{userSearchCriteria.username}"
                                     size="10"
                                     title="请输入用户名"/>
                    </h:panelGroup>

                    <h:panelGroup>
                        <p:outputLabel for="sex" value="性别："/>
                        <p:selectOneMenu id="sex" value="#{userSearchCriteria.sex}">
                            <f:selectItem itemLabel="" itemValue="" noSelectionOption="true"/>
                            <f:selectItems value="#{appResource.getSysCodeList('性别')}"
                                           var="v_sysCode"
                                           itemValue="#{v_sysCode.codeValue}"
                                           itemLabel="#{v_sysCode.codeName}"/>
                        </p:selectOneMenu>
                    </h:panelGroup>

                    <h:panelGroup>
                        <p:outputLabel for="birthdayBegin" value="生日："/>
                        <p:calendar id="birthdayBegin"
                                    value="#{userSearchCriteria.birthdayBegin}"
                                    locale="zh_CN"
                                    navigator="true"
                                    pattern="yyyy-MM-dd"
                                    showButtonPanel="true"
                                    showWeek="true"
                                    size="10"/>
                        <h:outputText value="～"/>
                        <p:calendar id="birthdayEnd"
                                    value="#{userSearchCriteria.birthdayEnd}"
                                    locale="zh_CN"
                                    navigator="true"
                                    pattern="yyyy-MM-dd"
                                    showButtonPanel="true"
                                    showWeek="true"
                                    size="10"/>
                    </h:panelGroup>
                </h:panelGrid>
            </p:fieldset>

            <p:toolbar>
                <f:facet name="left">
                    <p:commandButton value="查询"
                                     action="#{userQuery.search}"
                                     icon="ui-icon-search"
                                     update="@form"/>

                    <span class="ui-separator">
                        <span class="ui-icon ui-icon-grip-dotted-vertical"/>
                    </span>

                    <!--p:commandButton value="添加"
                                     action="userEdit?faces-redirect=true"
                                     icon="ui-icon-plus"
                                     immediate="true"/-->
                    <p:button value="添加"
                              outcome="userEdit"
                              icon="ui-icon-plus"/>

                    <!--p:commandButton value="批量删除"
                                     action="#{ucUserQuery.batchDelete}"
                                     icon="ui-icon-close"
                                     onclick="if(!confirm('批量删除选中的用户吗？')){return false;}"
                                     update="@form"/-->
                </f:facet>

                <f:facet name="right">
                    <p:commandButton value="导出"
                                     icon="ui-icon-calculator"
                                     ajax="false">
                        <p:dataExporter type="xls"
                                        target="resultTable"
                                        encoding="GBK"
                                        fileName="#{appResource.getFileName('用户', true)}"/>
                    </p:commandButton>
                    <p:commandButton value="导出2"
                                     icon="ui-icon-calculator"
                                     ajax="false">
                        <p:dataExporter type="xls"
                                        target="resultTable"
                                        encoding="GBK"
                                        fileName="user"/>
                    </p:commandButton>
                </f:facet>
            </p:toolbar>

            <p:dataTable id="resultTable"
                         value="#{userQuery.resultModel}"
                         var="v_user"
                         emptyMessage="找不到符合条件的用户"
                         lazy="true"
                         paginator="true"
                         paginatorPosition="both"
                         currentPageReportTemplate="查询到{totalRecords}条记录，本页显示{startRecord}～{endRecord}；第{currentPage}/{totalPages}页"
                         paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                         rows="5"
                         rowsPerPageLabel="每页行数"
                         rowsPerPageTemplate="5,10,20,50,100,200,500,1000"
                         rowIndexVar="rowIdx"
                         rowKey="#{v_user.userId}"
                         selectionMode="single"
                         selection="#{userQuery.selectedUser}"
                         stickyHeader="true"
                         disabledTextSelection="false"
                         draggableColumns="true"
                         resizableColumns="true">
                        <!--
                        stickyHeader="true"
                        -->
                <!--<p:column selectionMode="multiple"
                          styleClass="column-center"
                          exportable="false"/>-->

                <p:column styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="序号"/>
                    </f:facet>
                    <h:outputText value="#{rowIdx+1}"/>
                </p:column>

                <p:column sortBy="#{v_user.userId}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="用户ID" title="userId"/>
                    </f:facet>
                    <h:outputText value="#{v_user.userId}"/>
                </p:column>

                <p:column sortBy="#{v_user.username}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="用户名" title="username"/>
                    </f:facet>
                    <p:commandLink title="查看"
                                   update=":display"
                                   oncomplete="PF('dlg').show()">
                        <h:outputText value="#{v_user.username}"/>
                        <h:outputText class="ui-icon ui-icon-zoomin" style="display: inline-block"/>
                        <f:setPropertyActionListener value="#{v_user}" target="#{v_selectedUser}"/>
                    </p:commandLink>
                </p:column>

                <p:column sortBy="#{v_user.sex}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="性别" title="sex"/>
                    </f:facet>
                    <h:outputText value="#{appResource.getCodeName('性别', v_user.sex)}" title="#{v_user.sex}"/>
                </p:column>

                <p:column sortBy="#{v_user.birthday}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="生日" title="birthday"/>
                    </f:facet>
                    <h:outputText value="#{v_user.createTime}">
                        <f:convertDateTime pattern="yyyy-MM-dd"/>
                    </h:outputText>
                </p:column>

                <p:column sortBy="#{v_user.enabled}" styleClass="column-center">
                    <f:facet name="header">
                        <h:outputText value="是否启用" title="enabled"/>
                    </f:facet>
                    <h:outputText title="启用"
                                  class="ui-icon ui-icon-circle-check"
                                  style="display: inline-block"
                                  rendered="#{v_user.enabled}"/>
                    <h:outputText title="禁用"
                                  class="ui-icon ui-icon-circle-close"
                                  style="display: inline-block"
                                  rendered="#{!v_user.enabled}"/>
                    <h:outputText value="#{v_user.enabled ? '启用' : '禁用'}" title="#{v_user.enabled}"/>
                </p:column>

                <p:column styleClass="column-center" exportable="false">
                    <f:facet name="header">操作</f:facet>
                    <h:link title="修改" outcome="userEdit">
                        <f:param name="userId" value="#{v_user.userId}"/>
                        <h:outputText class="ui-icon ui-icon-pencil" style="display: inline-block"/>
                    </h:link>

                    <p:spacer width="4"/>
                    <p:commandLink title="删除"
                                   onclick="if (!confirm('删除“#{v_user.username}”吗？')) {return false;}"
                                   action="#{userQuery.deleteById(v_user.userId)}"
                                   update="@form"
                                   immediate="true">
                        <h:outputText class="ui-icon ui-icon-trash" style="display: inline-block"/>
                    </p:commandLink>
                </p:column>
            </p:dataTable>
        </h:form>

        <p:dialog id="display"
                  widgetVar="dlg"
                  draggable="true"
                  resizable="true"
                  closable="true"
                  minimizable="false"
                  maximizable="true"
                  modal="true"
                  position="center"
                  showEffect="explode"
                  hideEffect="explode"
                  appendTo="@(body)">

            <f:facet name="header">
                <h:outputText class="ui-icon ui-icon-person" style="display: inline-block"/>
                <h:outputText value="用户" title="Hi, RaTKiNG is here!"/>
            </f:facet>

            <p:panel>
                <h:panelGrid columns="4" columnClasses="grid-title,grid-normal,grid-title,grid-normal">
                    <h:outputText value="用户ID：" title="userId"/>
                    <h:outputText value="#{v_selectedUser.userId}"/>

                    <h:outputText value="用户名：" title="username"/>
                    <h:outputText value="#{v_selectedUser.username}"/>

                    <h:outputText value="性别：" title="sex"/>
                    <h:outputText value="#{appResource.getCodeName('性别', v_selectedUser.sex)}" title="#{v_selectedUser.sex}"/>

                    <h:outputText value="生日：" title="birthday"/>
                    <h:outputText value="#{v_selectedUser.birthday}">
                        <f:convertDateTime pattern="yyyy-MM-dd"/>
                    </h:outputText>

                    <h:outputText value="是否启用：" title="enabled"/>
                    <h:panelGroup>
                        <h:outputText title="启用"
                                      class="ui-icon ui-icon-circle-check"
                                      style="display: inline-block"
                                      rendered="#{v_selectedUser.enabled}"/>
                        <h:outputText title="禁用"
                                      class="ui-icon ui-icon-circle-close"
                                      style="display: inline-block"
                                      rendered="#{!v_selectedUser.enabled}"/>
                        <h:outputText value="#{v_selectedUser.enabled ? '启用' : '禁用'}" title="#{v_selectedUser.enabled}"/>
                    </h:panelGroup>

                    <h:outputText value="创建时间：" title="createTime"/>
                    <h:outputText value="#{v_selectedUser.createTime}">
                        <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/>
                    </h:outputText>

                    <h:outputText value="更新时间：" title="updateTime"/>
                    <h:outputText value="#{v_selectedUser.updateTime}">
                        <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"/>
                    </h:outputText>

                    <h:outputText value="版本：" title="version"/>
                    <h:outputText value="#{v_selectedUser.version}"/>
                </h:panelGrid>
            </p:panel>

            <f:facet name="footer">
                <div style="text-align: center">
                    <p:commandButton value="关闭"
                                     onclick="PF('dlg').hide()"
                                     icon="ui-icon-close"
                                     type="button"/>
                </div>
            </f:facet>
        </p:dialog>
    </ui:define>
</ui:composition>
